| default (1) | template <class T> const T& max (const T& a, const T& b); |
|---|---|
| custom (2) | template <class T, class Compare> const T& max (const T& a, const T& b, Compare comp); |
| default (1) | template <class T> const T& max (const T& a, const T& b); |
|---|---|
| custom (2) | template <class T, class Compare> const T& max (const T& a, const T& b, Compare comp); |
| initializer list (3) | template <class T> T max (initializer_list<T> il);template <class T, class Compare> T max (initializer_list<T> il, Compare comp); |
| default (1) | template <class T> constexpr const T& max (const T& a, const T& b); |
|---|---|
| custom (2) | template <class T, class Compare> constexpr const T& max (const T& a, const T& b, Compare comp); |
| initializer list (3) | template <class T> constexpr T max (initializer_list<T> il);template <class T, class Compare> constexpr T max (initializer_list<T> il, Compare comp); |
operator< (or comp, if provided) to compare the values.1
2
3
template <class T> const T& max (const T& a, const T& b) {
return (a<b)?b:a; // or: return comp(a,b)?b:a; for version (2)
}
bool. The value returned indicates whether the element passed as first argument is considered less than the second.operator<.1
2
3
4
5
6
7
8
9
10
11
// max example
#include <iostream> // std::cout
#include <algorithm> // std::max
int main () {
std::cout << "max(1,2)==" << std::max(1,2) << '\n';
std::cout << "max(2,1)==" << std::max(2,1) << '\n';
std::cout << "max('a','z')==" << std::max('a','z') << '\n';
std::cout << "max(3.14,2.73)==" << std::max(3.14,2.73) << '\n';
return 0;
}
max(1,2)==2
max(2,1)==2
max('a','z')==z
max(3.14,2.73)==3.14